// pages/webSite/webSite.js
import { lgRequest } from '../../utils/ajax'
import util from '../../utils/util'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    zhandianfuze:'',//站点负责人
    markers:[],
    longitude:'',
    latitude:'',
    mapCtx:null,
    qqmapsdk:'',
    isShowsatellite:false,
    statusBarHeight: getApp().globalData.statusBarHeight,
    titleBarHeight: getApp().globalData.titleBarHeight,
    sysInfo:getApp().globalData.sysInfo,
    isIphoneX:getApp().globalData.isIphoneX,
    keyWords:'',
    selectIndex:null,
    selectItem:{},
    isSHowSelect:true,
    isShowAllSelect:false,
    showOrderList:false,
    isSelectDay:true,
    kanCha:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/b6de0df7915e37f465877bc3b84538b0.png',
    allOptioner:[
      {
        name: '全部',
        color: '#4E81F0 ',
        icon: 'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/b5c09367ed670069b11a714bdc0662ed.png'
      },
      {
        name:'勘察',
        icon:'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/660695ef4c077f0d794f23e376b58e6f.png',
        color:'#F6AF00'
      },
      {
        name: '施工',
        color: '#07A4EC',
        icon: 'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/a1e3c761e058bd402e1c3de49c2d77cf.png'
      },
      {
        name: '交付',
        color: '#029E47',
        icon: 'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/5eb3349e5ab1417e45d80347aafbb8c7.png'
      },
      {
        name: '故障',
        color:'#E80010 ',
        icon: 'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/4a79febdd7bc928683e90ef534a5ea77.png'
      },
      {
        name: '拆除',
        color:'#FF6436',
        icon: 'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/a58bf8e41467b2d51ec59b7eee90c190.png'
      },
      {
        name: '添加',
        color: '#08B7B3',
        icon: 'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/bad02800d9b26c1e5a26ed9e65d0b6f8.png'
      },
    ],
    orderList:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/7894a02b181e5dae677cf4acf3e74004.png',
    selectDay:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/2687ed8098204efb6c45e14962edbc04.png',
    noSelectDay:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/375e71461a9dec9dfd8ee5291e0a165c.png',
    selectSatellite:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/5cb83962ac8c2e8c5088b6132716f19c.png',
    nosSlectSate:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/23/137b7e067ee70b08a1207adbb91f4083.png',
    toMap:"https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/02/2b9df4d67b60bf2f9037e30cc3aa546f.png",
    scale:15,
    // 一级
    kanCha1:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/21b5f2c1412d96fd2565778e0d29492f.png',
    shiGong1:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/9217f7ac015db312277e276c27e03915.png',
    chaiChu1:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/1f261dd1234d54d2b7c6b5922a63db86.png',
    jiaoFu1:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/b196b8010e9ca624bcdf199a2034b46b.png',
    guZhang1:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/bf46e93d495244a5cdb0fa2347ad2398.png',
    // 二级
    kanCha2:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/9f5af9457b35266ec3ed66ff302d9ed4.png',
    shiGong2:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/cf7cf5a8d89e831a4d0afe5fcd234912.png',
    chaiChu2:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/e9ec7fbfc844e3ae993e9c0b77017fa5.png',
    jiaoFu2:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/ccb995dfd70b91544cbe148a742dc37b.png',
    guZhang2:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/1c20aa36563bcc2d7462772e6009c6d7.png',
    // 三级
    kanCha3:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/edeaa8e1352e2f7b10945ff3736603cb.png',
    shiGong3:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/b8f3d0d0a53ef54cfe10caf72776e001.png',
    chaiChu3:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/8f9bced64babc568587e4d50dbe0d71f.png',
    jiaoFu3:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/e9cf93b827b684ccaeb8b03dc4468715.png',
    guZhang3:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/24/abcf853c5f9d5ecc75804f763673dbfc.png',
    rightImgIcon:'http://114.115.190.196:8082/profile/upload/2022/08/25/a6c6d09b626ffe0783cc658a899e48c6.png',
    shareImg:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/20/7c16fe32f8ed3f1ce246225098693aa8.png',
    stateTypeList:[
      {
        icon:'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/3f26068944c7733297e7f93bf12188e4.png',
        icon_active:'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/13589761c563a265805bc39db5ffe18b.png',
        name:'勘察',
        color:'#F9BF2E'
      },
      {
        icon:'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/1a6a5e18496bffb76339de5b5f2c47ba.png',
        icon_active:'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/3ccd1a92b567a5df3f46b98da61b9272.png',
        name:'施工',
        color:'#1A9CD9'
      },
      {
        icon:'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/ae638bba573613e2490261413ac2b32b.png',
        icon_active:'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/9dbe667ab5df1c2fe31ddf00cc7f028a.png',
        name:'交付',
        color:'#16B76F'
      },
      {
        icon:'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/5909649dd0651441ca8f8ee21a5636cb.png',
        icon_active:'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/689bce8d28506fc50558f85157acc25e.png',
        name:'故障',
        color:'#E81826'
      },
      {
        icon:'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/ed3f67bd7ffb1295d9257b417444b29b.png',
        icon_active:'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/8766acc0aa67b8c95fe569b049eab285.png',
        name:'拆除',
        color:'#FD7E5D'
      },
      //加了状态  别忘记换
      {
        icon:'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/b11e438f79f2dc290a3ff5be26d97804.png',
        icon_active:'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/83a9512dea1df3d2736505b9b58fa6ab.png',
        name:'停用',
        color:'#FD7E5D'
      },
    ],
    switchList:[
      {
        name:'未取电',
        name_active:'已取电',
        isSelect:false
      },
      {
        name:'未安装',
        name_active:'已安装',
        isSelect:false
      },
      {
        name:'未核电',
        name_active:'已核电',
        isSelect:false
      },
      {
        name:'未立杆',
        name_active:'已立杆',
        isSelect:false
      },
      {
        name:'未联网',
        name_active:'已联网',
        isSelect:false
      }
    ],
    switchListOne:[
      {
        name:'政府施工',
        name_active:'政府施工',
        isSelect:false
      },
      {
        name:'不可抗力',
        name_active:'不可抗力',
        isSelect:false
      },
      {
        name:'其他',
        name_active:'其他',
        isSelect:false
      },
    ],
    redBg:'https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/a6ffb5ce9a669ba8298398bef34e0e86.png',
    greenBg:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/1f7f77a9b26ba601732b436a140c1e69.png',
    whiteBg:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/f37e1fe6501f44eb5fb877eff35068f2.png',
    circle:'https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/ac0b6544db4ed907bf5444fc888409aa.png',
    selectIndexType:'',
    parentList:[],
    childrenList:[],
    siteListData:[],
    keyWords:'',
    showPop:false,
    scrollTop:0,
    isShowBottom:false,
    showloactionInfo:false,
    showSecondlevel:false,
    clickItemPostion:{},
    selectTagItem:{},
    selectTagIndex:'',
    selectPackIfo:{}, //选中的分组信息
    markerInfo:{},
    orderListList:[],
    mapScale:10,
    clickItemInfo:{},
    isSelectSiteCondition:"j",
    selectSiteCondition:"",
    searcherA:[
      {
        name: "落垡镇",
        id: "52"
      },
      {
        name: "杨税务乡",
        id: "51"
      },
      {
        name: "码头镇",
        id: "50"
      },
      {
        name: "东沽港镇",
        id: "49"
      },
      {
        name: "葛渔城镇",
        id: "48"
      },
      {
        name: "调河头乡",
        id: "47"
      },
      {
        name: "仇庄镇",
        id: "46"
      },
      {
        name: "高点",
        id: "23"
      },
      {
        name: "卡口",
        id: "22"
      },
      {
        name: "调河头",
        id: "29"
      },
      {
        name: "码头",
        id: "28"
      },
      {
        name: "葛渔城",
        id: "26"
      },
      {
        name: "东沽港",
        id: "25"
      },
      {
        name: "空站分组",
        id: "65"
      },
      {
        name: "开发分组1",
        id: "43"
      },
      {
        name: "开发分组2",
        id: "33"
      },
      {
        name: "环津界电子卡口",
        id: "54"
      },
      {
        name: "污水处理厂",
        id: "64"
      },
      {
        name: "其它渠",
        id: "63"
      },
      {
        name: "鲍邱河",
        id: "62"
      },
      {
        name: "三分干渠",
        id: "61"
      },
      {
        name: "一分干渠",
        id: "60"
      },
      {
        name: "总干渠",
        id: "59"
      },
      {
        name: "潮白河",
        id: "58"
      },
      {
        name: "B组",
        id: "57"
      },
      {
        name: "A组",
        id: "56"
      },
    ],
    searcherV:"",
  },
    // 查询站点状态施工进度
    constructionProgress() {
      let params = {
        siteId: this.data.clickItemPostion.id
      }
      console.log("123456", params)
      lgRequest("constructionProgress", params, {
        doSuccess: (r) => {
          console.log("施工状态", r)
          this.setData({
            switchList: r.data
          })
        }
      })
    },
  clickItem(e){
    console.log(e)
    this.data.parentList[e.target.dataset.index].isSelect = true
    this.setData({
      selectIndex: e.target.dataset.index,
      selectItem: e.target.dataset.item,
    })
    this.getChildrenList()
  },
  // input事件(内容改变时触发)
  inputC(e) {
    this.setData({
      searcherV: e.detail.value,
      keyWords: e.detail.value,
    })
    this.searchInput()
  },
  // 搜索功能
  searcher_a(){
    var res = this.data.searcherA.filter(item=>{
      if(item.name == this.data.searcherV){
        return item
      }else{
        wx.showToast({
          title: '查询成功，请稍后  ',
          icon:'none'
        })
        // this.setData({
        //   keyWords:""
        // })
      }
    })
    console.log(res);
    let selectPackIfo = {
      id: res[0].id,
      // id:"51",
    }
    console.log(this.data.parentList,'这是我需要的父元素');
    console.log(this.data.childrenList,'这是我需要的子元素');
    
    this.setData({
      // selectIndex: null,
      isSHowSelect:false,
      selectPackIfo:selectPackIfo,
      latitude: this.data.latitude,
      longitude: this.data.longitude,
      selectChIndex: 0,
    })
    this.siteList()
  },
  clickChildItem(e){
    console.log(e,'这是e');
    
    let selectPackIfo = e.currentTarget.dataset.item
    // debugger
    this.setData({
      // selectIndex: null,
      isSHowSelect:false,
      selectPackIfo:selectPackIfo,
      latitude: this.data.latitude,
      longitude: this.data.longitude,
      selectChIndex: e.target.dataset.index,
    })
    this.siteList()
  },
  showisSHowSelect(){
    this.setData({
      selectIndex: null,
      isSHowSelect: !this.data.isSHowSelect,
    })
    // console.log(!this.data.isSHowSelect)
    // this.data.isSHowSelect=!this.data.isSHowSelect

  },
  clickTag(e){
    let tagName = this.data.tagName;
    let index =  e.target.dataset.index ;
    tagName[index].typeCode = !tagName[index].typeCode
    
    this.setData({
      tagNameIndex :  e.target.dataset.index ,
      tagName
    })
  },
  showAllSelect(e){
    let selectIndex = e.target.dataset.index;
    this.setData({
      isShowAllSelect: !this.data.isShowAllSelect,
      selectTagItem:selectIndex?this.data.allOptioner[selectIndex]:{},
      selectTagIndex:selectIndex?selectIndex:''
    })
    if(selectIndex!=6){
      this.siteList()
    }
    switch (selectIndex){
      case 6:
        wx.navigateTo({
          url: '../minePage/addSite/addSite',
        })
        break;
    }
  },
  showOrderList(){
    this.setData({
      showOrderList: !this.data.showOrderList
    })
  },
  selectDayType(e){
    this.setData({
      isSelectDay: e.currentTarget.dataset.select
    })
  },
  rangeChange(e){
    let that = this
    this.data.mapCtx.getScale({
      success:function(res){
        that.setData({
          scale:res.scale
        })
      },
    })
  },
  /**
   * 点击标记点
   * @param {*} options 
   */
  async markerClick(e){
    let clickItem = (this.data.markers.filter(item=>item.id==e.markerId))[0]
    let markers = this.data.markers
    markers.forEach(item=>{
      if(item.id==e.markerId){
        item.beforeiconPath = item.iconPath
        item.beforewidth = item.width;
        item.beforeheight = item.height;
        let iconPath = `${item.pathName}3`
        item.iconPath = this.data[iconPath]
        item.width = 29.5;
        item.height = 38;
      } else {
        if(item.beforeiconPath){
          item.iconPath = item.beforeiconPath
          item.width = item.beforewidth;
          item.height = item.beforeheight;
          delete item.beforeiconPath
          delete item.beforewidth
          delete item.beforeheight
        }
      }
    })
    let clickItemInfo = [];
    try{
      clickItemInfo = await this.picStateList(clickItem.id,clickItem.state)
      console.log(clickItemInfo,'clickItemInfo')
    }catch(err){

    }
    this.setData({
      markers,
      clickItemPostion:clickItem,
      clickItemInfo:clickItemInfo,
      showloactionInfo:true,
      selectIndexType : clickItem.state,
    })
    this.constructionProgress()
  },
  //获取站点图片
  picStateList(id,state){
    return new Promise((resolve,reject)=>{
      let params = {
        siteId:id,
        state:state,
      }
      lgRequest('picStateList', params, {
        errAlert: false,
        doSuccess: r => {
          if (r.code == 200) {
            resolve(r.data)
          } else {
            wx.showToast({
              title: r.msg,
              icon: 'none'
            })
            reject()
          }
        },
        doComplete: r => {
        }
      })
    })
    
  },
  /**
   * 
   * 获取左侧列表信息} 
   */
  fList() {
    let params = {};
    lgRequest('fList', params, {
      errAlert: false,
      doSuccess: r => {
        if (r.code == 200) {
          console.log(r.data.list)
          this.setData({
            parentList : r.data.list
          })
        } else {
          wx.showToast({
            title: r.msg,
            icon: 'none'
          })
        }
      },
      doComplete: r => {
      }
    })
  },
  /**
   * 
   * @param {获取子集列表} options 
   */
  getChildrenList(){
    // debugger
    let params = {
      fatherId:this.data.selectItem.id
    }
    lgRequest('packetList', params, {
      errAlert: false,
      doSuccess: r => {
        if (r.code == 200&&r.data.length>=1) {
          this.setData({
            childrenList : r.data
          })
        } else {
          wx.showToast({
            title: r.msg,
            icon: 'none'
          })
        }
      },
      doComplete: r => {
      }
    })
  },
  /**
   * 站点信息
   */
  siteList(tag,states,name,ip){
    // console.log(111);
    if(tag||states||name||ip){
      let params = {
        packetId:this.data.selectPackIfo.id?this.data.selectPackIfo.id:(this.data.selectItem.id?this.data.selectItem.id:''),
        tag,
        states:states?states:'',
        name:name?name:'',
        ip:ip?ip:'',
      };
      console.log(params,'这是传参')
      lgRequest('siteList', params, {
        errAlert: false,
        doSuccess: r => {
          if (r.code == 200) {
            console.log(r);
            let markers = [];
            let flag = false
            if(this.data.markers.length>0){
              flag=true
              this.setData({
                markerInfo:this.data.markers[0]
              })
            } else {
              this.setData({
                mapScale:11
              })
            }
            r.data.forEach(item=>{
              if(item.state!=6){
                item.tag = item.tag?item.tag.split(','):''
                let itemGps = item.gps.split(',')
                let itemInfo = {
                  id:parseInt(item.id),
                  longitude:itemGps[0],
                  latitude:itemGps[1],
                  address:item.address,
                  // iconPath:this.data.kanCha3,
                  name:item.name,
                  stateName:item.stateName,
                  stateIcon :item.state?this.data.stateTypeList[item.state-1].icon_active:'',
                  width:flag?this.data.markerInfo.width:'9',
                  height:flag?this.data.markerInfo.height:'9',
                  tag:item.tag,
                  state:item.state
                }
                let iconPathInfo = this.changePathInfo(item)
                itemInfo.pathName = iconPathInfo.pathName
                itemInfo.iconPath = iconPathInfo.iconPath
                markers.push(itemInfo)
              }
            })
            this.setData({
              markers:markers,
              orderListList:r.data
            })
          } else {
            wx.showToast({
              title: r.msg,
              icon: 'none'
            })
          }
        },
        doComplete: r => {
        }
      })
    }else{
      let params = {
        packetId:this.data.selectPackIfo.id?this.data.selectPackIfo.id:'',
        tag:this.data.selectTagIndex?this.data.selectTagIndex:''
      }
      lgRequest('siteList', params, {
        errAlert: false,
        doSuccess: r => {
          if (r.code == 200) {
            console.log(r,'这是站点信息？');
            let markers = [];
            let flag = false
            if(this.data.markers.length>0){
              flag=true
              this.setData({
                markerInfo:this.data.markers[0]
              })
            } else {
              this.setData({
                mapScale:11
              })
            }
            r.data.forEach(item=>{
              if(item.state!=6){
                item.tag = item.tag?item.tag.split(','):''
                let itemGps = item.gps.split(',')
                let itemInfo = {
                  id:parseInt(item.id),
                  longitude:itemGps[0],
                  latitude:itemGps[1],
                  address:item.address,
                  // iconPath:this.data.kanCha3,
                  name:item.name,
                  stateName:item.stateName,
                  stateIcon :item.state?this.data.stateTypeList[item.state-1].icon_active:'',
                  width:flag?this.data.markerInfo.width:'9',
                  height:flag?this.data.markerInfo.height:'9',
                  tag:item.tag,
                  state:item.state
                }
                let iconPathInfo = this.changePathInfo(item)
                itemInfo.pathName = iconPathInfo.pathName
                itemInfo.iconPath = iconPathInfo.iconPath
                markers.push(itemInfo)
              }
            })
            this.setData({
              markers:markers,
              orderListList:r.data
            })
          } else {
            wx.showToast({
              title: r.msg,
              icon: 'none'
            })
          }
        },
        doComplete: r => {
        }
      })
    };
    

 
  },
  // 获取站点分组信息
  getSiteCondition(){
    let Authorization = getApp().globalData.Authorization;
    let server = getApp().globalData.server;
    wx.request({
      url: `${server}server/dictionaries/site_state`,
      header:{
        Authorization
      },
      success:(r)=>{
        console.log(r)
        let siteCondition = r.data.data;
        let quanbu = {
          valueId:"0",
          valueName:'全部',
        };
        siteCondition.unshift(quanbu)
        this.setData({
          siteCondition
        })
      }
    })
  },
  // 修改站点分组信息
  selectSiteCondition(e){
    let index = e.currentTarget.dataset.index;
    let item = e.currentTarget.dataset.item;
    let isSelectSiteCondition = index;
    let selectSiteCondition = item;
    this.setData({
      isSelectSiteCondition,
      selectSiteCondition
    })
  },
  changePathInfo(item){
    let iconPathInfo = {}
    switch(item.state){
      case '1':
        iconPathInfo.pathName = 'kanCha'
        iconPathInfo.iconPath = this.data.kanCha1
        return iconPathInfo
      case '2':
        iconPathInfo.pathName = 'shiGong'
        iconPathInfo.iconPath = this.data.shiGong1
        return iconPathInfo
      case '3':
        iconPathInfo.pathName = 'jiaoFu'
        iconPathInfo.iconPath = this.data.jiaoFu1
        return iconPathInfo
      case '4':
        iconPathInfo.pathName = 'guZhang'
        iconPathInfo.iconPath = this.data.guZhang1
        return iconPathInfo
      case '5':
        iconPathInfo.pathName = 'chaiChu'
        iconPathInfo.iconPath = this.data.chaiChu1
        return iconPathInfo

    }
  },
  /**
   * 
   * @param {站点详情} options 
   */
  itemDetail(e){
    console.log("页面传参",e);
    let item = encodeURIComponent(JSON.stringify(e.currentTarget.dataset.item));
    let packetId = encodeURIComponent(JSON.stringify(e.currentTarget.dataset.item.packetId));
    wx.navigateTo({
      url: `../minePage/stateDetail/stateDetail?zhanIdInfo=${item}&packetId=${packetId}`,
      // events: {
      //   // 定义A页面和B页面之间的通道事件
      //   PageAacceptDataFromPageB: function (data) {
      //     console.log('B页面返回给页面A的数据', data)
      //     let orderListList = this.data.orderListList
          
      //     let index = orderListList.findIndex((item)=>{
      //       item.id == data.id
      //     })
      //     orderListList[index] = data
      //     this.setData({
      //       orderListList
      //     })
      //   },
      //   // 定义A页面和C页面之间的通道事件
      //   PageAacceptDataFromPageC: function (data) {
      //     console.log('页面A收到C页面数据', data)
      //   }
      // },
    })
  },
  //信息筛选
  showRightPop(){
   
    console.log(this.data.showPop,'dfvdfvdf')
    let tagName = this.data.tagName
    tagName.forEach(item=>{
      item.typeCode=false
      
    })
    this.setData({
      showPop : !this.data.showPop,
      tagName ,
      // siteCondition 
    })
  },
  // 按标签搜索
  tagSearch(){
    
    let tagName = this.data.tagName;
    let tag = [];
    tagName.forEach(item=>{
    
      if(item.typeCode){
        
        tag.push(item.valueId)
        
      }
      
      
    })
    let states = this.data.selectSiteCondition.valueId
    this.siteList(tag.toString(),(states!=''&&states!="0")?states:'','',this.data.ip)
    
  
    setTimeout(()=>{
     
      this.showRightPop();
    },500)
     
  },
  clickSelectIndexType(e){
    this.setData({
      selectIndexType:e.currentTarget.dataset.type+1
    })
  },
  /**
   * 监听滚动
   * @param {*} options 
   */
  handletouchmove: function(event) {
    console.log('监听滑动') 
  },
 
  handletouchstart:function(event) {
    this.data.lastX = event.touches[0].pageX;
    this.data.lastY = event.touches[0].pageY;
  },
  handletouchend:function(event) {
    let currentY = event.changedTouches[0].pageY;
    let ty = currentY - this.data.lastY;
    if (ty < 0){
      if(!this.data.showSecondlevel){
        this.setData({
          showSecondlevel:true
        })
      }
    }
    else if (ty > 20) {
      console.log('尽力阿里',ty)
      if(this.data.showSecondlevel){
        this.setData({
          showSecondlevel:false
        })
        return
      }
      if(this.data.showloactionInfo){
        this.setData({
          showloactionInfo:false
        })
      }
    }
  },
  selectItemSwitch(e){
    let index = e.currentTarget.dataset.index;
    let switchList = this.data.switchList;
    switchList[index].value = switchList[index].value == 1 ? "0" : "1";
    let selectSwitchItem = e.currentTarget.dataset.item;
    this.setData({
      switchList,
      selectSwitchItem,
    });
    console.log("状态按钮传参", e.currentTarget.dataset)
    let params = {
      id: this.data.switchList[index].id,
      value: this.data.switchList[index].value,
    };
    lgRequest("modificationOfConstructionSchedule", params, {
      doSuccess: (r) => {
        console.log("修改成功", r)
      }
    })
  },
  selectItemSwitchOne(e){
    let index = e.currentTarget.dataset.index;
    let switchListOne = this.data.switchListOne;
    switchListOne[index].value = switchListOne[index].value == 1 ? "0" : "1";
    let selectSwitchItem = e.currentTarget.dataset.item;
    this.setData({
      switchListOne,
      selectSwitchItem,
    });
    console.log("状态按钮传参", e.currentTarget.dataset)
    let params = {
      id: this.data.switchListOne[index].id,
      value: this.data.switchListOne[index].value,
    };
    lgRequest("zhandiantingyon", params, {
      doSuccess: (r) => {
        console.log("修改成功", r)
      }
    })
  },
  resetTag(){
    let tagName = this.data.tagName;
    tagName.forEach(item=>
      item.typeCode = false)
    this.setData({
      // selectIndex:8,
      // selectChIndex:100,
      isSelectSiteCondition:'j',
      tagName,
      selectSiteCondition:'',
      ip:''
    })
    
  },
  /**
   * 巡查、联系人、记录
   * @param {*} options 
   */
  toOtherPage(e){
    let type = e.currentTarget.dataset.type
    let item = encodeURIComponent(JSON.stringify(this.data.clickItemPostion));
    let packetId = encodeURIComponent(JSON.stringify(this.data.clickItemPostion.packetId));
    switch(type){
      case '1':
        wx.navigateTo({
          url: '../minePage/freePatrol/freePatrol',
        })
        break;
      case '2':
        wx.navigateTo({
          url: `../minePage/stateDetail/stateDetail?type=2&zhanIdInfo=${item}&packetId=${packetId}`,
        })
        break;
      case '3':
        wx.navigateTo({
          url: `../minePage/stateDetail/stateDetail?type=3&zhanIdInfo=${item}&packetId=${packetId}`,
        })
        break;
      case '4':
        wx.navigateTo({
          url: `../minePage/stateDetail/stateDetail?zhanIdInfo=${item}&packetId=${packetId}`,
        })
        break;
    }
  },
    // 获取标签列表
    getTagList(){
      let server = getApp().globalData.server
      let Authorization = getApp().globalData.Authorization
      wx.request({
        url: `${server}server/dictionaries/site_tag`,
        header : {
          Authorization
        },
        success:(r)=>{
          let tagName = r.data.data
          tagName.forEach(item=>{
            if(item.valueId==1){
              item.color = "#6C8FE2"
            }
            if(item.valueId==5){
              item.color = "#E80015"
            }
            if(item.valueId==2){
              item.color = "#079547"
            }
            if(item.valueId==3){
              item.color = "#F76F06"
            }
            if(item.valueId==6){
              item.color = "#252778"
            }
            if(item.valueId==4){
              item.color = "#7B73B6"
            }
            if(item.valueId==8){
              item.color = "#0E71CB"
            }
            if(item.valueId==7){
              item.color = "#6C8FE2"
            }
            if(item.valueId==9){
              item.color = "#096CB2"
            }
            if(item.valueId==10){
              item.color = "#7AB6B3"
            }
            if(item.valueId==11){
              item.color = "#9C6EE7"
            }  
            if(item.valueId==12){
              item.color = "#685A51"
            } 
             if(item.valueId==13){
              item.color = "#E6697D"
            }  
            if(item.valueId==14){
              item.color = "#07BED8"
            }
          })
          this.setData({
            tagName
          })
        }
    })
  },
  getSearch(e){
    console.log(e)
    this.setData({
      getSearch:e.detail.value
    })
  },
  searchInput(e){
    let getSearch = this.data.getSearch || this.data.keyWords
    this.siteList('','',getSearch)
    // console.log(222);
  },
  getIp(e){
    this.setData({
      ip:e.detail.value
    })
  },
  
  // 测试组件内部数据
//     zz(e){
//   console.log(e)
// },
//   ss(e){
//   console.log(e)
// },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.constructionProgress()
    let that = this
    this.getSiteCondition()
    this.fList()
    // this.siteList() //站点信息
    app.watch(this, {
      scale: function (newVal) {
        if(newVal<=11){
          let markers = that.data.markers
          markers.forEach(item=>{
            let iconPath = `${item.pathName}1`
            item.iconPath = that.data[iconPath]
            item.width = 9,
            item.height = 9
          })
          setTimeout(()=>{
            that.setData({
              markers:markers
            })
          })
        } else if(11<newVal&&newVal<=13){
          let markers = that.data.markers
          markers.forEach(item=>{
            let iconPath = `${item.pathName}2`
            item.iconPath = that.data[iconPath]
            item.width = 11,
            item.height = 13
          })
          setTimeout(()=>{
            that.setData({
              markers:markers
            })
          })
        } else if(13<newVal&&newVal<=16){
          let markers = that.data.markers
          markers.forEach(item=>{
            let iconPath = `${item.pathName}3`
            item.iconPath = that.data[iconPath]
            item.width = 24.5,
            item.height = 31
          })
          setTimeout(()=>{
            that.setData({
              markers:markers
            })
          })
        } else {
          let markers = that.data.markers
          markers.forEach(item=>{
            let iconPath = `${item.pathName}3`
            item.iconPath = that.data[iconPath]
            item.width = 29.5,
            item.height = 38
          })
          setTimeout(()=>{
            that.setData({
              markers:markers
            })
          })
        }
      }
    })
    this.getTagList();//获取标签列表
    // this.getSite();//获取站点状态列表
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */

  onReady:function () {
    
    let that = this
    this.data.mapCtx = wx.createMapContext('myMap')
    this.data.mapCtx.getScale({
      success:function(res){
        that.setData({
          scale:res.scale
        })
      },
    })
    wx.getLocation({
      type: 'gcj02',
      success(res) {
        console.log(res,'dfvd')
        const latitude = res.latitude
        const longitude = res.longitude
        that.setData({
          latitude: latitude,
          longitude: longitude
        })
      }
    })
 
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // this.siteList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('fgbfgbfgb')
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      // title: '分享标题',
      // path: 'pages/home/index',
      // imageUrl: '/images/home.png',
      // success: (res) => {
      //   // 分享成功
      // },
      // fail: (res) => {
      //   // 分享失败
      // }clickItemPostion.address
      title:this.data.clickItemPostion.address,
      success:(res)=>{
        分享成功
        console.log(res);
      }
    }
  }
})